from django.conf.urls import url, include
from rest_framework.documentation import include_docs_urls
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework.routers import DefaultRouter
from users.views import UserViewSet
from users.views import AccountViewSet
from users.views import UserInfoApiView
from users.views import UserAuthGroupViewSet
from users.views import UserAuthGroupPermisstionApiView
from users.views import SystemHomeApiView
from users.views import LdapUserLogin
from deploy.views import DeployViewSet
from deploy.views import DeployOprationView
from deploy.views import ProjectNameListViewSet
from deploy.views import DeployHistoryView
from deploy.views import DeployWorkOrderViewSet
from deploy.views import DeployTypeViewSet
from deploy.views import DeployEnvsViewSet
from images.views import ImageViewSet
from images.views import ImageHistoryPushRecord
from images.views import ImageOpration
from databases.views import DatabaseViewSet
from databases.views import RedisOprationView
from systemd.views import RegistryViewSet
from systemd.views import RobotDtalkViewSet
from systemd.views import RobotConnectApiView
from systemd.views import RegistryConnectStatusApiView
from files.views import FileListViewSet
from files.views import FileUploadApiView
from applications.views import NamespaceApiView
from applications.views import PodsApiView
from applications.views import IngressApiView
from applications.views import DeploymentApiView
from product.views import ProductionNamespacedApiView
from product.views import ProductionPodsApiView
from product.views import ProductionDeploymentApiView
from product.views import ProductionDeploymentUpdateApiView
from product.views import ProductionDeploymentRollBackListApiView
from product.views import ProductionDeploymentRollBackApiView
from product.views import ProductionIngressApiView
from product.views import ProductionServiceApiView
from tools.views import LdapViewSet
from tools.views import LdapConnectTest

router = DefaultRouter()

# 用户
router.register(r'users', UserViewSet, base_name="users")
# 权限组
router.register(r'auth_group', UserAuthGroupViewSet, base_name="auth_group")
# 用户密码
router.register(r'account', AccountViewSet, base_name="account")
# 部署
router.register(r'deploy/manage', DeployViewSet, base_name="deploy")
router.register(r'deploy/opraion', DeployOprationView, base_name="opration")
router.register(r'deploy/history', DeployHistoryView, base_name="history")
router.register(r'deploy/projectNameList', ProjectNameListViewSet, base_name="projectNameList")
router.register(r'deploy/type', DeployTypeViewSet, base_name="type")
router.register(r'deploy/envs', DeployEnvsViewSet, base_name="envs")
# 发布工单
router.register(r'work_order', DeployWorkOrderViewSet, base_name="work_order")
# 镜像
router.register(r'image', ImageViewSet, base_name="image")
router.register(r'push_record', ImageHistoryPushRecord, base_name="push_record")
# 数据管理
router.register(r'databases/manage', DatabaseViewSet, base_name="databases")
# 系统设置
router.register(r'system/registry', RegistryViewSet, base_name="registry")  # 仓库信息
# 钉钉机器人
router.register(r'system/dtalk', RobotDtalkViewSet, base_name="dtalk")
# 文件列表
router.register(r'files', FileListViewSet, base_name="files")
# ldap设置
router.register(r'ldap_admin', LdapViewSet, base_name="ldap_conf")

urlpatterns = [
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
    url(r'^login/', obtain_jwt_token),
    url(r'^ldap/', LdapUserLogin.as_view(), name="ldap"),
    url(r'^ldap_test/', LdapConnectTest.as_view(), name="ldap_test"),
    url(r'^get_info/', UserInfoApiView.as_view(), name="get_info"),
    url(r'^home/', SystemHomeApiView.as_view(), name="home"),
    url(r'^databases/redis_opration/', RedisOprationView.as_view(), name="redis_opration"),
    url(r'^image/opration/', ImageOpration.as_view(), name="opration"),
    url(r'^system/connect/', RegistryConnectStatusApiView.as_view(), name='connect'),
    url(r'^system/robot/connect/(?P<id>[^/.]+)/$', RobotConnectApiView.as_view(), name='connect'),
    url(r'^auth_group/user_auth/', UserAuthGroupPermisstionApiView.as_view(), name='user_auth'),
    url(r'^files/upload/', FileUploadApiView.as_view(), name="upload"),
    url(r'^application/namespaces/', NamespaceApiView.as_view(), name="namespaces"),
    url(r'^application/pods/', PodsApiView.as_view(), name="pods"),
    url(r'^application/ingress/', IngressApiView.as_view(), name="ingress"),
    url(r'^application/deployment/', DeploymentApiView.as_view(), name="deployment"),
    url(r'^production/namespaced/', ProductionNamespacedApiView.as_view(), name="namespaced"),
    url(r'^production/pods/', ProductionPodsApiView.as_view(), name="pods"),
    url(r'^production/deployment/', ProductionDeploymentApiView.as_view(), name="deployment"),
    url(r'^production/deploy/', ProductionDeploymentUpdateApiView.as_view(), name="deploy"),
    url(r'^production/roll_back_list/', ProductionDeploymentRollBackListApiView.as_view(), name="roll_back_list"),
    url(r'^production/roll_back/', ProductionDeploymentRollBackApiView.as_view(), name="roll_back"),
    url(r'^production/ingress/', ProductionIngressApiView.as_view(), name="ingress"),
    url(r'^production/service/', ProductionServiceApiView.as_view(), name="ingress"),
    url(r'^', include(router.urls)),
    url(r'^docs/', include_docs_urls(title='OpsPlatform3.0开发文档'))
]
